package com.cskaoyan.controller;

import com.cskaoyan.bean.BasePageInfo;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketGoods;
import com.cskaoyan.bean.leihao.po.CreatePo;
import com.cskaoyan.bean.leihao.po.Update;
import com.cskaoyan.bean.leihao.vo.CatAndBrandVo;
import com.cskaoyan.bean.leihao.vo.GoodsDetailVo;
import com.cskaoyan.bean.leihao.vo.GoodsListVo;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.config.zhangshizhi.CountTime;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.service.impl.GoodsServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**商品管理模块中的商品管理Controller
 * @Auther: leihao
 * @Date: Created in 9:21 2022/6/27
 */
@RestController
@RequestMapping("admin/goods")
public class GoodsController {
    @Autowired
    GoodsService goodsService;

    @CountTime
    @RequiresPermissions(value ={"admin:goods:list","*"},logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo<MarketGoods> goodsList(BasePageInfo basePageInfo, Integer goodsId, String goodsSn, String name){
        CommonData<MarketGoods> goodsList = goodsService.getGoodsList(basePageInfo,goodsId,goodsSn,name);
        return BaseRespVo.ok(goodsList);
    }

    @CountTime
    @RequiresPermissions(value ={"admin:goods:detail","*"},logical = Logical.OR)
    @RequestMapping("detail")
    public BaseRespVo goodsDetail(Integer id){
        GoodsDetailVo goodsDetailVo = goodsService.getGoodsDetail(id);
        return BaseRespVo.ok(goodsDetailVo);
    }
    @CountTime
    @RequiresPermissions(value ={"admin:goods:catAndBrand","*"},logical = Logical.OR)
    @RequestMapping("catAndBrand")
    public BaseRespVo catAndBrand(){
        CatAndBrandVo catAndBrandVo = goodsService.getCatAndBrand();
        return BaseRespVo.ok(catAndBrandVo);
    }
    @CountTime
    @RequiresPermissions(value ={"admin:goods:delete","*"},logical = Logical.OR)
    @RequestMapping("delete")
    public BaseRespVo goodsDelete(@RequestBody MarketGoods marketGoods){
        goodsService.deleteGoodsById(marketGoods);
        return BaseRespVo.ok();
    }
    @CountTime
    @RequiresPermissions(value ={"admin:goods:update","*"},logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo goodsUpdate(@RequestBody Update update){
        goodsService.update(update);
        return BaseRespVo.ok();
    }
    @CountTime
    @RequiresPermissions(value ={"admin:goods:create","*"},logical = Logical.OR)
    @RequestMapping("create")
    public BaseRespVo goodsCreate(@RequestBody CreatePo createPo){
         goodsService.create(createPo);
         return BaseRespVo.ok();
    }
}
